package code1;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/16 20:52
 * 非递归查找法
 */
public class BinarySearch {

//    arr[left,right]范围中
    private static <E extends Comparable<E>> int search(E[] data,  E target) {

        int left = 0;
        int right = data.length -1;


        while (left <=right){
            int mid = left+(right-left)/2;
            if(data[mid].compareTo(target) ==0){
                return mid;
            }else if(data[mid].compareTo(target) < 0){
                left = mid +1;
            }else {
                right = mid -1;
            }
        }
        return -1;
    }
}
